/* 
 * File:   keyboardInterpreter.cpp
 * Author: dana
 * 
 * Created on March 6, 2010, 8:03 PM
 */

#include "keyboardInterpreter.h"
#include "SDL/SDL.h"
#include <stdio.h>


SDL_Event event;

keyboardInterpreter::keyboardInterpreter() {
}

void keyboardInterpreter::setController( controller* conin) {
    con = conin;
}

keyboardInterpreter::keyboardInterpreter(const keyboardInterpreter& orig) {
}

keyboardInterpreter::~keyboardInterpreter() {
}

void keyboardInterpreter::up() {
    con->up();
}

void keyboardInterpreter::down() {
    con->down();
}

void keyboardInterpreter::left() {
    con->left();
}

void keyboardInterpreter::right() {
    con->right();
}

void keyboardInterpreter::attack() {
    con->attack();
}

void keyboardInterpreter::jump() {
    con->jump();
}

void keyboardInterpreter::eject() {
    con->eject();
}

void keyboardInterpreter::pause() {
    con->pause();
}

void keyboardInterpreter::pollKeysForever() {
    // beware.  Once you pollKeysForever, you cannot stop.
    // Start this in its own thread.
    printf("What happen?\n");
    while ( quit == false ) {

        if ( SDL_PollEvent( &event )) {
            if ( event.type == SDL_KEYDOWN ) {
                switch( event.key.keysym.sym ){
                    case SDLK_UP: printf("ha"); up(); break;
                    case SDLK_DOWN: down(); break;
                    case SDLK_LEFT: left(); break;
                    case SDLK_RIGHT: right(); break;
                    case SDLK_z: attack(); break;
                    case SDLK_x: jump(); break;
                    case SDLK_c: eject(); break;
                    case SDLK_p: pause(); break;
                    case SDLK_q: quit = true; break;

                }
            }
            else if ( event.type == SDL_QUIT ) {
                quit = true;
            }
        }
       
    }
}